﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using STMS.Models.VModels;

namespace STMS.DAL
{
    public class ViewStoreRegionDAL:BQuery<ViewStoreRegionInfo>
    {
        /// <summary>
        /// 条件查询仓库分区信息
        /// </summary>
        /// <param name="storeId"></param>
        /// <param name="stateId"></param>
        /// <param name="keywords"></param>
        /// <param name="isDeleted"></param>
        /// <returns></returns>
        public List<ViewStoreRegionInfo> FindStoreRegion(int storeId, int stateId,
            string keywords, int isDeleted)
        {
            string cols = CreateSql.GetColsString<ViewStoreRegionInfo>("StoreId,TemperState,Remark,IsDeleted");
            List<ViewStoreRegionInfo> list = new List<ViewStoreRegionInfo>();
            string strWhere = $"IsDeleted = {isDeleted} ";
            if (storeId > 0)
                strWhere += $"and StoreId = {storeId} ";
            if (stateId > -1)
                strWhere += $"and TemperState = {stateId} ";
            if (!string.IsNullOrEmpty(keywords))
            {
                strWhere += "and (SRegionName like @keywords or SRegionNo like @keywords)";
                SqlParameter paras = new SqlParameter("@keywords", $"%{keywords}%");
                list = GetModelList(strWhere, cols, paras);
            }
            else
            {
                list = GetModelList(strWhere, cols);
            }
            return list;
        }     
    }     
}
